﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;

namespace Efcore.MultiTenant.Entity
{
    /// <summary>
    /// 实体模型扫描;默认实现,扫描继承BaseEntity的实体
    /// </summary>
    public interface IEntityScanner
    {
        List<Type> ScanTypeList();
    }

    /// <summary>
    /// 默认实现,扫描继承BaseEntity的实体
    /// </summary>
    public class EntityScanner : IEntityScanner
    {
        public List<Type> ScanTypeList()
        {
            return AppDomain.CurrentDomain.GetAssemblies().SelectMany(m => m.GetTypes()).Where(m => m.IsPublic && !m.IsInterface && !m.IsAbstract && !m.IsGenericType && m.IsClass && m.IsSubclassOf(typeof(BaseEntity))).ToList();
        }
    }
}
